package com.ruoyi.web.controller.rgpp;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rgpp.domain.Jibencompany;
import com.ruoyi.rgpp.service.IJibencompanyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 企业基本信息Controller
 * 
 * @author ruoyi
 * @date 2022-06-13
 */
@Controller
@RequestMapping("/rgpp/informationcompany")
public class JibencompanyController extends BaseController
{
    private String prefix = "rgpp/informationcompany";

    @Autowired
    private IJibencompanyService jibencompanyService;

    @RequiresPermissions("rgpp:informationcompany:view")
    @GetMapping()
    public String informationcompany(Jibencompany jibencompany,ModelMap mmp)
    {
        SysUser user = getSysUser();
        String sPhone=user.getLoginName();
        List<Jibencompany> list=new ArrayList<>();
        if (user.getUserId()==1){
            startPage();
            list = jibencompanyService.selectJibencompanyList(jibencompany);

        }else {
            jibencompany.setCard(sPhone);
            startPage();
            list=jibencompanyService.selectJibencompanyList(jibencompany);
        }
        mmp.put("jibencompany",list);
        return prefix + "/informationcompany";
    }

    /**
     * 查询企业基本信息列表
     */
    @RequiresPermissions("rgpp:informationcompany:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Jibencompany jibencompany)
    {
//        startPage();
//        List<Jibencompany> list = jibencompanyService.selectJibencompanyList(jibencompany);
//        return getDataTable(list);

        SysUser user = getSysUser();
        String sPhone=user.getLoginName();
        List<Jibencompany> list=new ArrayList<>();
        if (user.getUserId()==1){
            startPage();
            list = jibencompanyService.selectJibencompanyList(jibencompany);

        }else {
            jibencompany.setCard(sPhone);
            startPage();
            list=jibencompanyService.selectJibencompanyList(jibencompany);
        }
        return getDataTable(list);

    }

    /**
     * 导出企业基本信息列表
     */
    @RequiresPermissions("rgpp:informationcompany:export")
    @Log(title = "企业基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Jibencompany jibencompany)
    {
        List<Jibencompany> list = jibencompanyService.selectJibencompanyList(jibencompany);
        ExcelUtil<Jibencompany> util = new ExcelUtil<Jibencompany>(Jibencompany.class);
        return util.exportExcel(list, "企业基本信息数据");
    }



    /**
     * 新增企业基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业基本信息
     */
    @RequiresPermissions("rgpp:informationcompany:add")
    @Log(title = "企业基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Jibencompany jibencompany)
    {
        return toAjax(jibencompanyService.insertJibencompany(jibencompany));
    }

    /**
     * 修改企业基本信息
     */
    @RequiresPermissions("rgpp:informationcompany:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Jibencompany jibencompany = jibencompanyService.selectJibencompanyById(id);
        mmap.put("jibencompany", jibencompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业基本信息
     */
    @RequiresPermissions("rgpp:informationcompany:edit")
    @Log(title = "企业基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Jibencompany jibencompany)
    {
        return toAjax(jibencompanyService.updateJibencompany(jibencompany));
    }

    /**
     * 删除企业基本信息
     */
    @RequiresPermissions("rgpp:informationcompany:remove")
    @Log(title = "企业基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jibencompanyService.deleteJibencompanyByIds(ids));
    }
}
